package org.example;

public class Test1 {
    //leetcode 860  柠檬水找零 https://leetcode.cn/problems/lemonade-change/description/
    public boolean lemonadeChange(int[] bills) {
        int fiveCount = 0, tenCount = 0;
        for (int n : bills) {
            if (n == 5) fiveCount++;
            else if (n == 10) {
                if (fiveCount > 0) {
                    tenCount++;
                    fiveCount--;
                }else {
                    return false;
                }
            }else {
                if (fiveCount > 0 && tenCount > 0) {
                    fiveCount--;
                    tenCount--;
                }else if (fiveCount >= 3) {
                    fiveCount -= 3;
                }else {
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Test1 test1 = new Test1();
        int[] arr = {5,5,10,10,5,20,5,10,5,5};
        test1.lemonadeChange(arr);
        System.out.println(666);
    }
}
